/*
 * BlackLightning.PluginLib.Modules.IPlugin
 * Andy Tidball
 * 
 * Project: Black Lightning Plugin Library
 * Copyright: GNU General Public License
 */

using System;
using BlackLightning.PluginLib;

namespace BlackLightning.PluginLib.Modules {
	/// <summary>
	/// Defines the interface between Black Lightning and plugins it can load.
	/// </summary>
	public interface IPlugin : IPacketHandler {
		/// <summary>
		/// Called by Black Lightning to retrieve the value of a Property of the IPlugin.
		/// </summary>
		/// <param name="Property">The property to retrieve the value for.</param>
		/// <returns>The value of the requested property.</returns>
		object GetProperty(PluginProperty Property);
	}

	/// <summary>
	/// An attribute that tags Assemblies and defines which of its classes are Black Lightning Plugins.
	/// </summary>
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=false)]
	public class BLPluginAttribute : Attribute {
		// member data
		private Type _Type; // the type that is an IPlugin

		/// <summary>
		/// Creates a new BLPluginAttribute.
		/// </summary>
		/// <param name="Type">A type that implements IPlugin and wishes to be visible to Black Lightning.</param>
		public BLPluginAttribute(Type Type) {
			_Type = Type;
		}

		/// <summary>
		/// Gets or sets the type that implements IPlugin and wishes to be visible to Black Lightning.
		/// </summary>
		public Type Type {
			get {
				return _Type;
			}
			set {
				_Type = value;
			}
		}
	}

	/// <summary>
	/// An enumeration of all the properties that an IPlugin might have.
	/// </summary>
	public enum PluginProperty {
		/// <summary>
		/// (string) The text that should be displayed when the user requests help about the IPlugin.
		/// </summary>
		HelpText,

		/// <summary>
		/// (bool) True if the plugin should receive any packets bound for any of its modules, false if it should not.
		/// </summary>
		ReceiveModulePackets,

		/// <summary>
		/// (bool?) Whether or not the plugin wants to receive OptionValueChangedMessages for internal Black Lightning options related to it.
		/// </summary>
		ReceiveInternalOptionUpdates
	}
	
	/// <summary>
	/// A helper class that implements IPlugin and provides helper functionality to derived classes.
	/// </summary>
	public abstract class Plugin : PacketHandler, IPlugin {
		/// <summary>
		/// Gets the value of one of the Plugin's properties.
		/// </summary>
		/// <param name="Property">The property to retrieve the value of.</param>
		/// <returns>The value of the requested property.</returns>
		public abstract object GetProperty(PluginProperty Property);
	}
}
